/*
 *  Copyright 2020-2021 Li Fei
 *
 *  Licensed under the Apache License, Version 2.0 (the "License");
 *  you may not use this file except in compliance with the License.
 *  You may obtain a copy of the License at
 *
 *  http://www.apache.org/licenses/LICENSE-2.0
 *
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  limitations under the License.
 */
package com.pengshun.modules.api.coal.controller;

import com.fasterxml.jackson.annotation.JsonView;
import com.pengshun.modules.api.coal.para.CoalBinessPara;
import com.pengshun.modules.api.coal.para.MerchantCoalPara;
import com.pengshun.modules.api.coal.para.MerchantPara;
import com.pengshun.modules.api.coal.service.MerchantCoalService;
import com.pengshun.modules.api.coal.service.dto.MerchantCoalDto;
import com.pengshun.modules.api.coal.validator.*;
import com.pengshun.modules.common.PagePara;
import com.pengshun.modules.common.ReslutView;
import com.pengshun.modules.domain.User;
import com.pengshun.modules.security.Authorization;
import com.pengshun.modules.security.CurrUserInfo;
import com.pengshun.modules.common.BaseResult;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import io.swagger.annotations.*;
import springfox.documentation.annotations.ApiIgnore;

/**
 * @author lifei
 * @date 2020-11-12
 **/
@RestController
@RequiredArgsConstructor
@Api(tags = "商户煤炭管理")
@RequestMapping("/api/merchantCoal")
@ApiIgnore
public class MerchantCoalController     {

    private final MerchantCoalService merchantCoalService;

    @ApiOperation(value = "根据商户id查询煤炭销售列表")
    @GetMapping(value = "/info/id")
    @JsonView(ReslutView.aView.class)
    @ApiImplicitParam(name = "merchantId", value = "商户id", dataType = "int", required = true, paramType = "query")
    public BaseResult selectListById(@ApiIgnore @Validated(value = {Third.class}) MerchantPara para) throws Exception {
        BaseResult res = merchantCoalService.selectListBytId(para.getMerchantId());
        return res;
    }

//    @ApiOperation(value = "根据状态查询煤炭销售列表")
//    @GetMapping(value = "/info/status")
//    @JsonView(ReslutView.aView.class)
//    @ApiImplicitParams({
//            @ApiImplicitParam(name = "status", value = "状态(0:未发布,状态 1：正常；2:删除)", dataType = "int", paramType = "query"),
//            @ApiImplicitParam(name = "page", value = "当前页", dataType = "int", required = true, paramType = "query"),
//            @ApiImplicitParam(name = "size", value = "条数", dataType = "int", required = true, paramType = "query")
//    })
//    @Authorization
//    public BaseResult selectListByStatus(@ApiIgnore @CurrUserInfo User user, @ApiIgnore MerchantPara para) throws Exception {
//        BaseResult res = merchantCoalService.selectListByStatus(user.getId(), para);
//        return res;
//    }

    @ApiOperation(value = "条件查询煤炭销售列表")
    @GetMapping(value = "/info/by")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "status", value = "默认不传 0营业中,1暂停营业", dataType = "int", paramType = "query"),
            @ApiImplicitParam(name = "provinceId", value = "默认不传 省份id ", dataType = "int", paramType = "query"),
            @ApiImplicitParam(name = "cityId", value = "默认不传 城市id ", dataType = "int", paramType = "query"),
            @ApiImplicitParam(name = "districtId", value = "默认不传 区县编码id ", dataType = "int", paramType = "query"),
            @ApiImplicitParam(name = "page", value = "当前页", dataType = "int", required = true, paramType = "query"),
            @ApiImplicitParam(name = "size", value = "条数", dataType = "int", required = true, paramType = "query"),
            @ApiImplicitParam(name = "lngX", value = "经度", dataType = "double",   paramType = "query"),
            @ApiImplicitParam(name = "latY", value = "纬度", dataType = "double",  paramType = "query"),
            @ApiImplicitParam(name = "level", value = "1优质2普通", dataType = "int",  paramType = "query"),
            @ApiImplicitParam(name = "sort", value = "1最新发布 2价格排序", dataType = "int",  paramType = "query"),
            @ApiImplicitParam(name = "categoryCode", value = "煤种", dataType = "string",  paramType = "query"),
            @ApiImplicitParam(name = "categoryName", value = "煤种", dataType = "string",  paramType = "query"),
            @ApiImplicitParam(name = "mineMouthId", value = "煤矿", dataType = "string",  paramType = "query"),
            @ApiImplicitParam(name = "name", value = "煤炭名称 ", dataType = "string",  paramType = "query"),
            @ApiImplicitParam(name = "calorificValue", value = "热值", dataType = "string",  paramType = "query"),
            @ApiImplicitParam(name = "coalTechnologyCode", value = "热值", dataType = "string",  paramType = "query"),
            @ApiImplicitParam(name = "allSulphur", value = "硫分", dataType = "string",  paramType = "query"),
            @ApiImplicitParam(name = "serchHuifen", value = "灰分", dataType = "string",  paramType = "query"),
//            @ApiImplicitParam(name = "name", value = "商户名称 ", dataType = "string", paramType = "query"),
//            @ApiImplicitParam(name = "merchantCategoryId", value = "商户类别id", dataType = "int", required = true, paramType = "query"),
//            @ApiImplicitParam(name = "sort", value = "默认不传 1煤炭数排序 2货运数排序 3营业状态排序 ", dataType = "int", paramType = "query"),

    })
    @JsonView(ReslutView.aView.class)
    public BaseResult selectListBy(@ApiIgnore @Validated(value = {Third.class}) CoalBinessPara para) throws Exception {
        BaseResult res = merchantCoalService.selectListBy(para);
        return res;
    }

    @ApiOperation("查询商户煤炭详情")
    @ApiImplicitParam(name = "merchantCoalId", value = "商户煤炭id", dataType = "int", required = true, paramType = "query")
    @GetMapping(value = "/detil")
    public BaseResult selectCoalDetil(@Validated(value = {First.class}) MerchantCoalPara para) throws Exception {
        BaseResult res = merchantCoalService.selectCoalDetil(para.getMerchantCoalId());
        return res;
    }


    @ApiOperation(value = "煤炭保存")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "mineMouthId", value = "矿口id", dataType = "int", required = true, paramType = "query"),
            @ApiImplicitParam(name = "mineMouthName", value = "矿口名名称 ", dataType = "string", required = true, paramType = "query"),
            @ApiImplicitParam(name = "categoryId", value = "分类id", dataType = "int", required = true, paramType = "query"),
            @ApiImplicitParam(name = "categoryName", value = "分类名称 ", dataType = "string", required = true, paramType = "query"),
            @ApiImplicitParam(name = "coalCategoryId", value = "煤种id", dataType = "int", required = true, paramType = "query"),
            @ApiImplicitParam(name = "coalCategoryName", value = "煤种名称 ", dataType = "string", required = true, paramType = "query"),

            @ApiImplicitParam(name = "coalId", value = "煤炭id ", dataType = "int", required = true, paramType = "query"),
            @ApiImplicitParam(name = "coalName", value = "煤炭名称 ", dataType = "string", required = true, paramType = "query"),
            @ApiImplicitParam(name = "sellPrice", value = "价格", dataType = "double", required = true, paramType = "query"),
            @ApiImplicitParam(name = "coalNumber", value = "煤炭数量", dataType = "double", required = true, paramType = "query"),
            @ApiImplicitParam(name = "lowNumber", value = "最低采购数量", dataType = "int", required = true, paramType = "query"),
            @ApiImplicitParam(name = "isTax", value = "0不含税1含税", dataType = "string", required = true, paramType = "query"),

            @ApiImplicitParam(name = "producingArea", value = "产地 ", dataType = "string", required = true, paramType = "query"),
            @ApiImplicitParam(name = "delivery", value = "交割地 ", dataType = "string", required = true, paramType = "query"),
            @ApiImplicitParam(name = "deliveryWay", value = "交货方式 ", dataType = "string", required = true, paramType = "query"),
            @ApiImplicitParam(name = "deliveryId", value = "交货id ", dataType = "string", required = true, paramType = "query"),
            @ApiImplicitParam(name = "coalTechnologyName", value = "煤炭工艺 ", dataType = "string", required = true, paramType = "query"),
            @ApiImplicitParam(name = "coalTechnologyCode", value = "煤炭工艺编码 ", dataType = "string", required = true, paramType = "query"),
            @ApiImplicitParam(name = "overTime", value = "结束日期yyyy-MM-dd ", dataType = "string", required = true, paramType = "query"),
            @ApiImplicitParam(name = "coalPic", value = "煤炭图片 ", dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "coalPicTwo", value = "煤炭图片 ", dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "coalPicThree", value = "煤炭图片 ", dataType = "string", paramType = "query"),

            @ApiImplicitParam(name = "laboratoryTime", value = "化验时间 ", dataType = "string", required = true, paramType = "query"),
            @ApiImplicitParam(name = "laboratoryBillPic", value = "化验单图片 ", dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "laboratoryCompany", value = "化验单单位 ", dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "linkman", value = "联系人 ", dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "linkmanPhone", value = "联系人电话 ", dataType = "string", paramType = "query"),

            @ApiImplicitParam(name = "wholeWater", value = "全水 ", dataType = "string", required = true, paramType = "query"),
            @ApiImplicitParam(name = "nsValue", value = "内水 ", dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "serchHuifen", value = "干基灰分 ", dataType = "string", required = true, paramType = "query"),
            @ApiImplicitParam(name = "kfValue", value = "空干基挥发 ", dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "sfValue", value = "收到基挥发 ", dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "gfValue", value = "干燥无灰基挥发 ", dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "allSulphur", value = "含硫量 ", dataType = "string", required = true, paramType = "query"),
            @ApiImplicitParam(name = "jzValue", value = "焦渣特征 ", dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "gtValue", value = "固定碳 ", dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "kwValue", value = "空干基高位 ", dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "swValue", value = "收到基低位 ", dataType = "string", paramType = "query"),
    })
    @PostMapping(value = "/save")
    @Authorization
    public BaseResult save(@ApiIgnore @CurrUserInfo User user, @ApiIgnore @Validated(value = {Sixth.class}) MerchantCoalDto form) throws Exception {
        form.setUserId(user.getId());
        BaseResult res = merchantCoalService.save(form);
        return res;
    }


    @ApiOperation(value = "查询煤炭销售列表")
    @GetMapping(value = "/list")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "status", value = "默认不传 0营业中,1暂停营业", dataType = "int", paramType = "query"),
            @ApiImplicitParam(name = "page", value = "当前页", dataType = "int", required = true, paramType = "query"),
            @ApiImplicitParam(name = "size", value = "条数", dataType = "int", required = true, paramType = "query"),

    })
    @Authorization
    public BaseResult coalList(@ApiIgnore @CurrUserInfo User user, PagePara para) throws Exception {
       para.setUserId(user.getId());
        BaseResult res = merchantCoalService.selectCoalList(para);
        return res;
    }

    @ApiOperation(value = "煤炭商品详情")
    @GetMapping(value = "/coal-detil")
    @ApiImplicitParam(name = "merchantCoalId", value = "煤炭商品id", dataType = "string", required = true, paramType = "query")
    public BaseResult coalDetil(@ApiIgnore @Validated(value = {First.class}) MerchantCoalPara para) throws Exception {
        BaseResult res = merchantCoalService.selectMerchantCoalDetil(para);
        return res;
    }


    @ApiOperation(value = "煤炭修改")
    @PostMapping(value = "/update")
    @Authorization
    public BaseResult update(@ApiIgnore @CurrUserInfo User user, @ApiIgnore @Validated(value = {Sixth.class}) MerchantCoalDto form) throws Exception {
        form.setUserId(user.getId());
        BaseResult res = merchantCoalService.update(form);
        return res;
    }
    @ApiOperation(value = "煤炭删除")
    @PostMapping(value = "/delete")
    @Authorization
    @ApiImplicitParam(name = "merchantCoalId", value = "煤炭商品id ", dataType = "int", required = true, paramType = "query")
    public BaseResult delete(@ApiIgnore @Validated(value = {First.class}) MerchantCoalPara para) throws Exception {
        BaseResult res = merchantCoalService.delete(para.getMerchantCoalId());
        return res;
    }

    @ApiOperation(value = "煤炭发布")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "merchantCoalId", value = "煤炭商品id", dataType = "string", required = true, paramType = "query"),
    })
    @PostMapping(value = "/issue")
    @Authorization
    @ApiImplicitParam(name = "merchantCoalId", value = "煤炭商品id ", dataType = "int", required = true, paramType = "query")
    public BaseResult issue(@ApiIgnore @Validated(value = {First.class}) MerchantCoalPara para) {
        BaseResult res = merchantCoalService.issue(para.getMerchantCoalId());
        return res;
    }

    @ApiOperation(value = "煤炭上架/下架")
    @PostMapping(value = "/show")
    @Authorization
    @ApiImplicitParams({
            @ApiImplicitParam(name = "merchantCoalId", value = "煤炭商品id ", dataType = "int", required = true, paramType = "query"),
            @ApiImplicitParam(name = "isShow", value = "0-下架；1-上架 ", dataType = "int", required = true, paramType = "query"),
    })
    public BaseResult show(@ApiIgnore @Validated(value = {Second.class}) MerchantCoalPara para) {
        BaseResult res = merchantCoalService.show(para);
        return res;
    }



}